import 'dart:convert' show json;

import 'package:freedom/entity/abstract_formart.dart';

import 'package:freedom/util/data_type.dart';

class MetaRoomEntity<T> implements AbstractFormart {
  MetaRoomEntity({
    this.type,
    this.roomRule,
    this.code,
  });

  factory MetaRoomEntity.empty() {
    return MetaRoomEntity();
  }

  factory MetaRoomEntity.fromJson(Map<String, dynamic>? jsonRes) {
    if (jsonRes == null) {
      return MetaRoomEntity();
    }
    return MetaRoomEntity(
      type: asT<String>(jsonRes['type']),
      roomRule: asT<T>(jsonRes['roomRule']),
      code: asT<String>(jsonRes['code']),
    );
  }

  String? type;
  T? roomRule;
  String? code;

  Map<String, dynamic> toJson() => <String, dynamic>{
        'roomType': type,
        'roomRule': roomRule,
        'code': code,
      };

  @override
  String toString() {
    return json.encode(this);
  }

  @override
  MetaRoomEntity caseToEntity(Map<String, dynamic> jsonRes) =>
      MetaRoomEntity.fromJson(jsonRes);
}
